package com.team.communication;

import com.team.client_server.ConnectClient;
import com.team.client_server.ServerMessage;
import com.team.cluedo.Game;
import com.team.cluedo.fc.Cluedo;



public class AnalyseurDeMessageClient {

	ConnectClient session;

	public AnalyseurDeMessageClient(ConnectClient session) {
		super();
		this.session = session;
	}
	
	public void traiterMessage(ServerMessage message){
		
		if (message.getRequest() == ServerRequest.GAME_CREATION_OK) {
			
			Game.cluedo.setWait();
		}
		if (message.getRequest() == ServerRequest.GAME_NAME_ALREADY_USED) {
			Game.cluedo.setCreatedGameFalse();
			Game.cluedo.setWait();
		}
		if (message.getRequest() == ServerRequest.GAME_JOIN_OK) {
			//Game.cluedo.setWait();
		}
		if (message.getRequest() == ServerRequest.GAME_FULL) {
			Game.cluedo.setJoinGamesFalse();
			Game.cluedo.setWait();
		}
		if (message.getRequest() == ServerRequest.SEND_GAMES) {
			String[] names = message.getParam();
			Game.cluedo.setExistGames(names);
		}
		if (message.getRequest() == ServerRequest.CHOOSE_CHARACTER) {
			//Game.cluedo.setWait();
			Game.cluedo.choosePerso();
		}
		
		// choose character
		if (message.getRequest() == ServerRequest.PAWN_OK) {
			Game.cluedo.waitMyTurn();
			if(message.getParam().length != 0){
				Game.cluedo.setMyCards(message.getParam());
			}
		}
		
		if (message.getRequest() == ServerRequest.PAWN_ALREADY_USED) {
			Game.cluedo.setChooseCharacterFalse();
		}
		
		if(message.getRequest() == ServerRequest.IT_IS_THE_TURN_OF){
			if(message.getParam()[0].equalsIgnoreCase(Game.cluedo.getName())){
				Game.cluedo.startTurn();
			}else{
				Game.cluedo.waitMyTurn(message.getParam()[0]);
			}
		}
		
		if(message.getRequest() == ServerRequest.SEND_DIRECTION){
			Game.cluedo.setDirection(message.getParam());
			Game.cluedo.setWait();
		}
		if(message.getRequest() == ServerRequest.SEND_MAKE_SUGGESTION){
			if(message.getParam().length != 0){
				Game.cluedo.setMakeSuggestionTrue(message.getParam()[0]);
			}else{
				Game.cluedo.waitForFinishedTurn();
			}
		}
		
		//caller of card
		if(message.getRequest() == ServerRequest.SEND_NO_ASKED_CARD){
			Game.cluedo.setAskedCard();
		}
		
		if(message.getRequest() == ServerRequest.SEND_ASKED_CARD){
			Game.cluedo.setAskedCard(message.getParam()[0]);
		}
		
		//sender of card
		if(message.getRequest() == ServerRequest.SUGGESTED_CARD){
			//demande de carte a montrer
			Game.cluedo.setSuggestedCards(message.getParam());
			//Game.cluedo.suggestedCards();
			
			
			//Game.cluedo.setWait();
		}
	}
}
